from dataclasses import dataclass
from typing import Tuple, List
from static_configuration import picture_style, scene_description, default_voice_type, max_concurrent_workers


@dataclass
class VideoConfig:
    """视频相关配置"""
    size: Tuple[int, int] = (720, 1280)
    default_fps: int = 24
    segment_fps: int = 12


@dataclass
class SubtitleConfig:
    """字幕相关配置"""
    max_chars_per_line: int = 30
    max_lines: int = 2
    min_duration: float = 1.0
    max_duration: float = 5.0
    font_size: int = 11
    stroke_width: int = 3
    margin_bottom: int = 20
    margin_horizontal: int = 20
    embed_to_video: bool = False
    # 带字幕生成
    hardcode_to_video: bool = False

    @property
    def max_chars_per_segment(self) -> int:
        return self.max_chars_per_line * self.max_lines


@dataclass
class LLMConfig:
    """LLM API相关配置"""
    base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
    model: str = "kimi-k2-250711"
    temperature: float = 0.7
    max_tokens: int = 1024
    system_prompt: str = """<role>戏剧化图片提示词生成专家</role>

<instruction>
  根据用户提供的故事片段，生成具有强烈戏剧张力的图片生成提示词，重点突出人物间的情感互动和冲突关系。
</instruction>

<guidelines>
  - 去除文案中血腥、暴力、色情、涉政、低俗与不雅内容以及任何可能引起不适、心理恐慌的敏感元素，输出时去掉可能包含血腥、暴力、色情、涉政、低俗与不雅内容以及任何可能引起不适、心理恐慌句式
  - 必须使用近景(close-up)或中景(medium shot)构图，严格避免远景和空镜头
  - 突出人物之间的情感交流、对立或互动关系
  - 增强戏剧化效果，通过表情、肢体语言、光影等元素营造张力
  - 根据故事情节选择最具冲突性或情感高潮的瞬间
  - 使用富有表现力的视觉语言，如对比强烈的光影、紧张的构图
  - 确保人物在画面中占据主导地位，避免背景抢夺注意力
  - 描述具体的情感状态和微表情，增强戏剧感染力
  - 必须是{picture_style}，不要出现其他风格
</guidelines>

<workflow>
  1. 分析故事片段，识别关键人物和核心冲突点
  2. 确定最具戏剧张力的场景瞬间
  3. 选择合适的镜头角度(近景或中景)突出人物互动
  4. 描述人物表情、姿态和情感状态
  5. 添加光影、色彩等视觉元素增强戏剧效果
  6. 构建完整的图片生成提示词
</workflow>

<output_format>
  - 直接提供完整的英文图片生成prompt
  - 开头明确镜头类型(close-up shot/medium shot)
  - 详细描述人物表情、动作和情感状态
  - 包含光影、构图等戏剧化视觉元素
  - 结尾强调整体戏剧氛围和情感张力
</output_format>

<examples>
  <example>
    <user_query>
      {scene_description}
    </user_query>
    <assistant_response>
      {picture_style},{scene_description}
    </assistant_response>
  </example>
</examples>""".format(picture_style=picture_style, scene_description=scene_description)


@dataclass
class ImageGenConfig:
    """图片生成API相关配置"""
    base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
    model: str = "doubao-seedream-3-0-t2i-250415"
    size: str = "1280x720"
    response_format: str = "url"


@dataclass
class TTSConfig:
    """TTS API相关配置"""
    api_url: str = "http://47.90.179.219:8501/tts_url"
    default_voice_type: str = default_voice_type.replace('.mp3', '').replace('.MP3', '')
    voice_mapping: dict = None

    def __post_init__(self):
        if self.voice_mapping is None:
            self.voice_mapping = {
                "英文_男声_磁性硬朗": "/app/audio_prompts/磁性硬朗-男声.MP3",
                "middle_male_en_antoni": "/app/audio_prompts/middle_male_en_antoni.mp3",
                "youth_female_en_bella": "/app/audio_prompts/youth_female_en_bella.mp3",
                "middle_male_en_josh": "/app/audio_prompts/middle_male_en_josh.mp3",
                "英文_男声_黑帮腹黑老大": "/app/audio_prompts/黑帮腹黑老大-男声.MP3",
                "youth_female_en_jessica": "/app/audio_prompts/youth_female_en_jessica.mp3",
                "中文_男声_张震": "/app/audio_prompts/张震-男-旁白.wav",
                "沉稳男声": "/app/audio_prompts/沉稳男声.MP3",
                "严肃抱怨-女声": "/app/audio_prompts/严肃抱怨-女声.MP3",
                "youth_female_en_river": "/app/audio_prompts/youth_female_en_river.MP3",
                "middle_male_en_will": "/app/audio_prompts/middle_male_en_will.MP3",
                "middle_male_en_liam": "/app/audio_prompts/middle_male_en_liam.MP3",
            }


@dataclass
class ProcessingConfig:
    """处理相关配置"""
    max_concurrent_workers: int = max_concurrent_workers
    animation_effects: List[str] = None

    def __post_init__(self):
        if self.animation_effects is None:
            # self.animation_effects = ["ken_burns", "zoom_in", "zoom_out", "slide_left", "slide_right"]
            self.animation_effects = ["zoom_in", "zoom_out"]


@dataclass
class AppConfig:
    """应用全局配置"""
    video: VideoConfig = None
    subtitle: SubtitleConfig = None
    processing: ProcessingConfig = None
    llm: LLMConfig = None
    image_gen: ImageGenConfig = None
    tts: TTSConfig = None

    def __post_init__(self):
        if self.video is None:
            self.video = VideoConfig()
        if self.subtitle is None:
            self.subtitle = SubtitleConfig()
        if self.processing is None:
            self.processing = ProcessingConfig()
        if self.llm is None:
            self.llm = LLMConfig()
        if self.image_gen is None:
            self.image_gen = ImageGenConfig()
        if self.tts is None:
            self.tts = TTSConfig()


# 全局配置实例
config = AppConfig()
